<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>唯一性检查示例</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f5f5f5;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .container {
            background-color: #ffffff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
            width: 400px;
            border-radius: 10px;
            text-align: center;
        }

        h1 {
            color: #333;
            font-size: 24px;
            margin-bottom: 20px;
        }

        p {
            color: #666;
            font-size: 16px;
            margin-bottom: 20px;
        }

        .input-container {
            margin-bottom: 20px;
        }

        .input-container input {
            padding: 10px;
            width: 80%;
            font-size: 16px;
            border: 2px solid #ccc;
            border-radius: 5px;
        }

        .input-container button {
            margin-top: 10px;
            padding: 10px 20px;
            background-color: #007BFF;
            border: none;
            color: white;
            font-size: 16px;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .input-container button:hover {
            background-color: #0056b3;
        }

        .result {
            font-size: 18px;
            font-weight: bold;
            margin-top: 20px;
        }

        .result.success {
            color: green;
        }

        .result.failure {
            color: red;
        }

        .info {
            font-size: 14px;
            color: #999;
        }
    </style>
</head>

<body>
    <div class="container">
        <h1>唯一性检查</h1>
        <p>输入一个数字列表，检查是否所有数字都唯一：</p>
        <div class="input-container">
            <input type="text" id="inputList" placeholder="请输入以逗号分隔的数字" />
            <button onclick="checkUniqueness()">检查唯一性</button>
        </div>
        <div class="result" id="result"></div>
        <div class="info">
            <p>示例输入：1, 2, 3, 4, 5</p>
            <p>如果数字重复，则返回“不唯一”。</p>
        </div>
    </div>

    <script>
        // 实现唯一性检查函数
        const allUniqueBy = (arr, fn) => arr.length === new Set(arr.map(fn)).size;

        // 检查唯一性的函数
        function checkUniqueness() {
            const inputValue = document.getElementById('inputList').value.trim();
            if (!inputValue) {
                alert('请输入数字列表');
                return;
            }

            // 将输入的字符串转为数字数组
            const arr = inputValue.split(',').map(item => item.trim());

            // 调用 allUniqueBy 检查唯一性
            const result = allUniqueBy(arr, item => item); // 根据每个数字本身来判断唯一性

            // 显示结果
            const resultDiv = document.getElementById('result');
            if (result) {
                resultDiv.textContent = '所有数字都唯一！';
                resultDiv.classList.remove('failure');
                resultDiv.classList.add('success');
            } else {
                resultDiv.textContent = '存在重复的数字！';
                resultDiv.classList.remove('success');
                resultDiv.classList.add('failure');
            }
        }
    </script>
</body>

</html>